< previous page page_294 next page >

Page 294
RtlMoveMemory API function is declared as well. This function takes two memory addresses and simply copies the number of bytes specified from the source address to the destination address.
' MemoryTutorial  A Quick Memory Demo Program
' Copyright © 1998 by Desaware Inc.  All Rights Reserved

Option Explicit
Private Declare Sub RtlMoveMemory Lib "kernel32" (ByVal Dest As _
Long, ByVal Source As Long, ByVal Count As Long)

Dim I As Integer
Dim L As Long
Dim F As Single
Dim D As Double
Dim C As Currency
Dim b As Byte
Dim V As Variant
Dim S As String

Private Sub Form_Load()
   I = 5
   L = 5
   F = 5
   D = 5
   C = 5
   S = 5
   b = 5
   V = 5
End Sub
The GetDataString function is what we use to examine the contents of memory. You pass it a memory address and a number of bytes. It starts at the address specified by the Address parameter and copies each byte in turn into a Byte variable called thisbyte.2 The thisbyte variable is converted into a hexadecimal string using the Hex$ function. Let's say thisbyte contains &H8F. In this case, Hex$(thisbyte) would return 8F. If thisbyte contains the number 5, Hex$(thisbyte) returns 5. In order to keep things even, we add an extra zero if the first nibble of thisbyte
7017a6ead0e3c4111b47a554df321e9f.gif 7017a6ead0e3c4111b47a554df321e9f.gif
2 Purists will note that this function is possibly the least efficient way of displaying memory data. In a real application, I would have copied the data into a byte array and scanned through the bytes one at a time. But the approach shown here, although slow, does clearly illustrate the task at handand this is a tutorial, after all.

 
< previous page page_294 next page >